package com.common.app.widget.mybanner;

import static com.common.base.config.AppConfig.GLIDE_FADE_IN_TIME;
import android.content.Context;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory;
import com.common.app.R;
import com.common.app.widget.mybanner.loader.ImageLoader;

public class GlideImageLoader extends ImageLoader {

    private Context mContext;

    private int mW = 1280;
    private int mH = 720;

    public GlideImageLoader() {
    }

    public GlideImageLoader(int mW, int mH) {
        this.mW = mW;
        this.mH = mH;
    }

    public GlideImageLoader(Context context) {
        this.mContext = context;
    }

    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {

        RequestOptions options = new RequestOptions();
//        options.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
        options.error(R.mipmap.ic_logo_launcher);
        //具体方法内容自己去选择，次方法是为了减少banner过多的依赖第三方包，所以将这个权限开放给使用者去选择
        Glide.with(context.getApplicationContext())
                .load(path.toString())
                .apply(options)
                .transition(DrawableTransitionOptions.with(new DrawableCrossFadeFactory.Builder(GLIDE_FADE_IN_TIME).setCrossFadeEnabled(true).build()))//渐入动画效果
                .into(imageView);
    }


}
